(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.companyRating.deleteRejectController', deleteController);
	deleteController.$inject = [ '$scope', 'Constants', 'layoutConfig', 'validatorConfig', 'gridService', 'authService', 'modalService',
			'companyRatingService' ];
	function deleteController($scope, Constants, layoutConfig, validatorConfig, gridService, authService, modalService, companyRatingService) {
		var ctrl = this, params = $scope.$stateParams.params;
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.companyRating = {};
		ctrl.companyRating.ratingtypes = ctrl.companyRating.ratingtypes || [];

		ctrl.init = function() {
			
			authService.deleteReject(params).then(function(response) {
				if (response.data && response.data.model && response.data.task) {
					ctrl.companyRating = response.data.model;
					ctrl.companyRating.taskId = response.data.task.taskId;
					
					companyRatingService.initRatingTypeQaItemAndQaAdj(ctrl, layoutConfig, 'Y');
				}
			});
		};

		ctrl.deleteRejectSubmit = function() {
			modalService.openConfirmDialogs({
				'messages' : [ {msg : 'title.dialog.confirm.delete', args : [ctrl.companyRating.primaryKey]} ],
				'btnCallback' : {
					'ok' : function(response) {
						authService.deleteRejectSubmit(ctrl.companyRating).then(deleteSuccessful, deleteFailed);
					}
				}
			});
		};

		ctrl.deleteRejectCancel = function() {
			modalService.openConfirmDialogs({
				'messages' : [ {msg : 'title.dialog.confirm.cancel', args : [ctrl.companyRating.primaryKey]} ],
				'btnCallback' : {
					'ok' : function() {
						authService.deleteRejectCancel(ctrl.companyRating).then(cancelSuccessful, cancelFailed);
					}
				}
			});
		};

		function deleteSuccessful(response) {
			modalService.openAcknowledgeDialogs({
				'messages' : [ 'title.dialog.successful.delete' ],
				'btnCallback' : {
					'close' : function() {
						$scope.go('cda.workflow.wfSetup.list');
					}
				},
				'redirections' : [ {
					'name' : 'title.infobar.workflow.list',
					'state' : 'cda.workflow.wfSetup.list',
					'params' : {}
				}, {
					'name' : 'title.infobar.companyrating.list',
					'state' : 'cda.companyRating.list',
					'params' : {}
				}]
			});
		}

		function deleteFailed(response) {
			modalService.openErrorDialogs({
				'messages' : response.error
			});
		}

		function cancelSuccessful(response) {
			modalService.openAcknowledgeDialogs({
				'messages' : [ 'title.dialog.successful.cancel' ],
				'btnCallback' : {
					'close' : function() {
						$scope.go('cda.workflow.wfSetup.list');
					}
				},
				'redirections' : [ {
					'name' : 'title.infobar.workflow.list',
					'state' : 'cda.workflow.wfSetup.list',
					'params' : {}
				}, {
					'name' : 'title.infobar.companyrating.list',
					'state' : 'cda.companyRating.list',
					'params' : {}
				}]
			});
		}

		function cancelFailed(response) {
			modalService.openErrorDialogs({
				'messages' : response.error
			});
		}
	}
})(angular);
